
package com.trial.area.task;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.trial.area.trade.entity.TradeRecordVO;
import com.trial.area.trade.service.TradeRecordService;

/**
 * 交易定时任务
 *
 * @author 朱国军
 * @version 2016年8月17日
 */
@Component
public class TradeTask {
    
    private Logger logger = LoggerFactory.getLogger(TradeTask.class);

    @Autowired
    private TradeRecordService tradeRecordService;

    @Scheduled(cron = "0 0 4 * * ?")
    public void cancleTrade() {
        logger.info("24小时内未支付订单定时取消job 开始执行");
        List<TradeRecordVO> tradeList = tradeRecordService.queryNoPayTrade();
        if (tradeList != null && tradeList.size() > 0) {
            logger.info("24小时内未支付订单定时取消,取消订单数" + tradeList.size());
            for (TradeRecordVO tradeRecord : tradeList) {
                try {
                    tradeRecordService.cancleTrade(tradeRecord);
                } catch (Exception e) {
                    logger.error("定时任务取消订单出错，订单号：" + tradeRecord.getTradeId(), e);
                }
            }
        }
    }
}
